﻿@model Apps.Models.Flow.Flow_StepModel
@using Apps.Common;
@using Apps.Models.Flow;
@using Apps.Web.Core;
@using Apps.Models.Sys;
@using Apps.Locale;
@using Apps.Models.Enum;
@{
    ViewBag.Title = "创建";
    Layout = "~/Views/Shared/_Index_LayoutEdit.cshtml";
    Flow_FormModel formModel = (Flow_FormModel)ViewBag.Form;
    List<permModel> perm = null;

}

<div id="modalwindow" class="easyui-window" data-options="modal:true,closed:true,minimizable:false,shadow:false"></div>
 
<table style="height: 457px;width:100%">
    <tr>
        <td style="width: 480px; border-right: 1px #ccc solid; vertical-align: top">
            @using (Html.BeginForm())
            {
            @Html.HiddenFor(model => model.FormId)
            @Html.HiddenFor(model => model.Id)
           
                <table class="formtable" >
                    <tbody>
                        <tr>
                            <td colspan="3">
                                <div class="mvctool bgb">
                                    @Html.ToolButton("btnSave", "fa fa-plus", Resource.Create, ref perm, "Save", true) 
                                    @Html.ToolButton("btnReturn", "fa fa-reply", Resource.Reply, false)
                                </div>
                            </td>
                        </tr>
                        <tr>
                            <th>
                                    @Html.LabelFor(model => formModel.Name, 0)：
                            </th>
                            <td colspan="2">
                                @Html.DisplayFor(model => formModel.Name) 
                            </td>
                        </tr>
                        <tr>
                            <th>
                                @Html.LabelFor(model => model.Name,0)：
                            </th>
                            <td>
                                @Html.EditorFor(model => model.Name) 
                               
                            </td>
                        </tr>
                        <tr>
                            <th>
                                @Html.LabelFor(model => model.Remark)：
                            </th>
                            <td colspan="2">
                                @Html.TextAreaFor(model => model.Remark, new { @style = "width:270px;height:40px" })
                            </td> 
                        </tr> 
                        <tr>
                            <th>
                                @Html.LabelFor(model => model.Sort)：
                            </th>
                            <td colspan="2">
                                @Html.EditorFor(model => model.Sort)
                               
                            </td>
                        </tr> 
                        <tr>
                            <th>
                                @Html.LabelFor(model => model.FlowRule)：
                            </th>
                            <td>
                                <select id="FlowRule" name="FlowRule">
                                    <option value="@((int)FlowRuleEnum.Customer)">自行指定人</option>
                                    <option value="@((int)FlowRuleEnum.Lead)">按上级</option>
                                    <option value="@((int)FlowRuleEnum.Position)">按职位</option>
                                    <option value="@((int)FlowRuleEnum.Department)">按部门</option>
                                    <option value="@((int)FlowRuleEnum.Person)">按人员</option>
                                </select>
                               
                            </td>
                        </tr>
                        <tr id="ruleExecution" style="display: none">
                            <th>
                                @Html.LabelFor(model => model.Execution)：
                            </th>
                            <td colspan="2">
                                @Html.HiddenFor(model => model.Execution)
                                <input id="ExecutionName" disabled="disabled" type="text" style="width: 240px" />
                                <a class="fa fa-plus" id="selExc" href="#"></a>
                               
                            </td>
                        </tr>

                        <tr>
                            <th>
                                @Html.LabelFor(model => model.IsAllCheck)：
                            </th>
                            <td colspan="2">
                                @Html.CheckBoxFor(model => model.IsAllCheck, new { @checked = "checked" })
                                <span class="gray">启用后，当步骤下所有人需要都通过表单才算通过</span>
                            </td>

                        </tr> 
                        <tr>
                            <th>
                                @Html.LabelFor(model => model.CompulsoryOver)：
                            </th>
                            <td colspan="2">
                                @Html.CheckBoxFor(model => model.CompulsoryOver)
                                <span class="gray">审批人是否可以强制完成整个流程</span>
                            </td>
                        </tr>
                        <tr>
                            <th>
                                @Html.LabelFor(model => model.IsEditAttr)：
                            </th>
                            <td colspan="2">
                                @Html.CheckBoxFor(model => model.IsEditAttr)
                                <span class="gray">审批者是否可以编辑发起者的申请</span>
                            </td>
                        </tr>
                      
                    </tbody>
                </table>
                @Html.ValidationSummary()
            } 
        </td>
        <td style="width: 412px;" valign="top" id="stepAccordionlist"> 
        </td>
    </tr>
</table>

<script type="text/javascript">
    $(function () {
        $.ajaxSetup({ cache: false });

        var idx = @(formModel.stepList.Count()) +1; 
         
        $('#Sort').val(idx);

        $("#btnSave").click(function () {
            //if ($("form").valid()) {
                $.ajax({
                    url: "@Url.Action("EditStep")",
                    type: "Post",
                    data: $("form").serialize(),
                    dataType: "json",
                    success: function (data) {
                        if (data.type == 1)
                        { 
                            var num = parseInt($("#Sort").val());
                            $.ajaxSetup({ cache: false });
                            $("#stepAccordionlist").load("../../Flow/Form/StepAccordion?formid=@( Model.FormId)&stepname=第" + num + "步：" + $("#Name").val());
                            $("#Sort").val(num + 1);
                        }
                        $.messageBox5s(Lang.Tip, data.message);
                    }
                });
            //}
            return false;
        });

        $("#FlowRule").change(function () {
            $("#Execution").val("");
            $("#ExecutionName").val("");
            if ($("#FlowRule").val() == "@((int)FlowRuleEnum.Lead)" || $("#FlowRule").val() == "@((int)FlowRuleEnum.Customer)") {
                $("#ruleExecution").hide();
            } else if ($("#FlowRule").val() == "@((int)FlowRuleEnum.Position)") {
                $("#selExc").html("审批职位");
                $("#ruleExecution").show();
            }
            else if ($("#FlowRule").val() == "@((int)FlowRuleEnum.Department)") {
                $("#selExc").html("审批部门");
                $("#ruleExecution").show();
            } else if ($("#FlowRule").val() == "@((int)FlowRuleEnum.Person)") {
                $("#selExc").html("审批人员");
                $("#ruleExecution").show();
            }
        });

        $("#selExc").click(function () {
            var html = $("#selExc").html()
            if (html == "审批人员") {
                $("#modalwindow").html("<iframe width='100%' height='100%' scrolling='no' frameborder='0'' src='/SysHelper/UserLookUp'></iframe>");
                $("#modalwindow").window({ title: '选择人员', width: 720, height: 428, iconCls: 'fa fa-plus' }).window('open');
            } else if (html == "审批职位") {
                $("#modalwindow").html("<iframe width='100%' height='100%' scrolling='no' frameborder='0'' src='/SysHelper/PosMulLookUp'></iframe>");
                $("#modalwindow").window({ title: '选择职位', width: 720, height: 428, iconCls: 'fa fa-plus' }).window('open');
            } else if (html == "审批部门") {
                $("#modalwindow").html("<iframe width='100%' height='100%' scrolling='no' frameborder='0'' src='/SysHelper/DepMulLookUp'></iframe>");
                $("#modalwindow").window({ title: '选择部门', width: 420, height: 438, iconCls: 'fa fa-plus' }).window('open');
            }
        });

        $("#btnReturn").click(function () {
            window.parent.frameReturnByReload('StepList',true);
            window.parent.frameReturnByClose();
        });

        $("#stepAccordionlist").load("../../Flow/Form/StepAccordion?formid="+ "@( Model.FormId)");
    });

    function DeleteStep(stepId)
    {
        $.messager.confirm(index_lang_tip, '你要删除当前步骤及条件吗？', function (r) {
            if (r) {
                $.post("@Url.Action("DeleteStep")?id=" + stepId, function (data) {//从数据库删除
                    if (data.type == 1)
                    {
                        $.ajaxSetup({ cache: false });
                        $("#stepAccordionlist").load("../../Flow/Form/StepAccordion?formid="+ "@( Model.FormId)");
                    }
                    $.messageBox5s(Lang.Tip, data.message);
                }, "json");

            }
        });
    }

    function EditStep(stepId)
    {
        $.messager.confirm(index_lang_tip, '你要编辑当前步骤吗？', function (r) {
            if (r) {
                $("#Id").val(stepId); 
            }
        });
    }

    function SetSelResult(result,resultName)
    {
        $("#Execution").val(result);
        $("#ExecutionName").val(resultName);
    }
    function GetSelResult()
    {
        var arrayObj = new Array()
        arrayObj[0]= $("#Execution").val();
        arrayObj[1]= $("#ExecutionName").val();
        return arrayObj;
    }
    //ifram 返回
    function frameReturnByClose() {
        $("#modalwindow").window('close');
    }
</script>